package hu.myandroidlife.adapter;

import hu.myandroidlife.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AdapterTextAndImage extends BaseAdapter {

	private Integer[] mImageInteger = { R.drawable.grid_payout,
			R.drawable.grid_bill, R.drawable.grid_report,
			R.drawable.grid_account_book, R.drawable.grid_category,
			R.drawable.grid_user, R.drawable.grid_payout, R.drawable.grid_bill,
			R.drawable.grid_report, R.drawable.grid_account_book,
			R.drawable.grid_category, R.drawable.grid_user };

	private String[] mImageString = { "记录消费", "查询消费", "统计管理", "帐本管理", "类别管理",
			"人员管理", "记录消费", "查询消费", "统计管理", "帐本管理", "类别管理", "人员管理" };
	private Context mContext;

	/**
	 * 构造器，主要用来传递数据，将所需要的数据作为形参
	 * 
	 * @param mContext
	 */
	public AdapterTextAndImage(Context mContext) {
		super();
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		return mImageString.length;
	}

	@Override
	public Object getItem(int position) {
		return mImageString[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder _Holder;
		if (convertView == null) {
			LayoutInflater _LayoutInflater = LayoutInflater.from(mContext);
			convertView = _LayoutInflater.inflate(
					R.layout.adapter_item_text_and_image, null);

			_Holder = new Holder();
			_Holder.ivIcon = (ImageView) convertView.findViewById(R.id.ivIcon);
			_Holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
			convertView.setTag(_Holder);

		} else {
			_Holder = (Holder) convertView.getTag();
		}

		_Holder.ivIcon.setImageResource(mImageInteger[position]);
		LinearLayout.LayoutParams _LayoutParams = new LinearLayout.LayoutParams(
				50, 50);
		_Holder.ivIcon.setLayoutParams(_LayoutParams);
		_Holder.ivIcon.setScaleType(ImageView.ScaleType.FIT_XY);

		_Holder.tvName.setText(mImageString[position]);

		return convertView;
	}

	private class Holder {
		ImageView ivIcon;
		TextView tvName;
	}

}
